package com.xh.easyretry.listener;

import com.xh.easyretry.annotations.XHRetry;
import com.xh.easyretry.common.XHRetryContext;
import com.xh.easyretry.common.XHRetryResult;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
public class RetryFailedListener<T extends XHRetryResult> extends RetryListener<T> {

    @Override
    public void listen(T t) {
        XHRetryContext retryContext = t.getRetryContext();
        XHRetry xhRetry = retryContext.getXhRetry();
        if (Objects.isNull(xhRetry)) {
            throw new IllegalArgumentException("xhRetry is null");
        }
        String retryFailedListenerMethodName = xhRetry.retryFailedListener();
        doWithSpecifyMethod(retryContext, retryFailedListenerMethodName);
    }
}
